package com.itheima.leetcode.od.c.logicalsimulation;

import java.util.*;

/**
 * <h3>CPU算力分配</h3>
 */
public class CPUComputingPowerAllocation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取输入
        String[] counts = scanner.nextLine().split(" ");
        int L1 = Integer.parseInt(counts[0]);
        int L2 = Integer.parseInt(counts[1]);

        // 获取A组CPU列表并计算总算力
        String[] cpusAStr = scanner.nextLine().split(" ");
        int[] cpusA = new int[L1];
        long totalA = 0;
        for (int i = 0; i < L1; i++) {
            cpusA[i] = Integer.parseInt(cpusAStr[i]);
            totalA += cpusA[i];
        }

        // 获取B组CPU列表并存入Map，同时计算总算力
        String[] cpusBStr = scanner.nextLine().split(" ");
        Map<Integer, Integer> cpuCountB = new HashMap<>();
        long totalB = 0;
        for (int i = 0; i < L2; i++) {
            int cpu = Integer.parseInt(cpusBStr[i]);
            totalB += cpu;
            cpuCountB.put(cpu, cpuCountB.getOrDefault(cpu, 0) + 1);
        }

        // 对A组CPU排序，确保找到最小的可能解
        Arrays.sort(cpusA);

        // 计算差值的一半
        long half = Math.round((totalA - totalB) / 2.0);

        // 遍历A组CPU寻找解
        for (int cpuA : cpusA) {
            int neededCpuB = cpuA - (int)half;
            if (cpuCountB.containsKey(neededCpuB)) {
                System.out.println(cpuA + " " + neededCpuB);
                break;
            }
        }

        scanner.close();
    }
}